<?php

namespace App\Services;

use App\Model\Normal;
use Hyperf\Guzzle\HandlerStackFactory;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Utils\ApplicationContext;
use GuzzleHttp\Client;
use AopCertClient;
use AlipayConfig;

class DeviceService
{
    private static $tcpUri = 'http://39.106.226.249:9003';



    public static function postTcp($path,$data,$type = 'form_params', $charset = 'UTF-8'){
        try {
            // 创建HTTP客户端
            $container = \Hyperf\Utils\ApplicationContext::getContainer();
            $handlerStackFactory = $container->get(HandlerStackFactory::class);
            $handlerStack = $handlerStackFactory->create();
            $client = new Client(['handler' => new CoroutineHandler($handlerStack)]);

            $response = $client->post(self::$tcpUri.$path, [
                'headers' => [
                    'Content-Type' => 'application/x-www-form-urlencoded;charset='.$charset,
                ],
                $type => $data
            ]);
            return $response;
            // 获取响应内容
            // $responseData = json_decode($response->getBody()->getContents(), true);
            // 根据响应处理结果
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage());
        }
    }
}
